/**
 * 公用方法提取
 * @type {{}}
 */
var commonUtils = {
    /**
     * 调用验证错误提示公用方法
     * @param isValidFlag  状态，Boolean型,true或false
     * @param errorDec  错误信息描述，
     * @param teskKey
     */
    isValidThorwError: function(isValidFlag, errorDec) {
        var isSmsCodeCorrectFunc = function() {
            return isValidFlag;
        }
        var getSmsCodeErrorMsgFunc = function() {
            return errorDec;
        }
        assertTrueOrThrowException(isValidFlag, isSmsCodeCorrectFunc, getSmsCodeErrorMsgFunc)
    },
    /**
     * 获取月份第一天和最后一天
     * @param monthIndex
     * @returns {any[]}
     */
    getFirstDayAndLastDay : function(monthIndex) {
        var startAndEnd=new Array(2);
        var cal = Calendar.getInstance();
        var weekYear = cal.get(Calendar.YEAR);
        var month = cal.get(Calendar.MONTH) - monthIndex;//获取月份
        var nomo = Math.abs(month)^12;
        if(nomo == 0){
            month = month+12;
            weekYear = cal.get(Calendar.YEAR) -1;//获取年份
        }
        cal.set(Calendar.YEAR,weekYear);
        cal.set(Calendar.MONTH,month);
        var sdf = new SimpleDateFormat("yyyy-MM-dd");
        var actualMinimum = cal.getActualMinimum(Calendar.DATE);
        //格式化日期
        //设置日历中月份的最小天数
        cal.set(Calendar.DAY_OF_MONTH,actualMinimum);
        var firstDate = sdf.format(cal.getTime());
        startAndEnd.add(firstDate);
        var actualMaximum = cal.getActualMaximum(Calendar.DATE);
        if(monthIndex == 0){
            var lastDate = sdf.format(cal.getTime());
        }else{
            //设置日历中月份的最小天数
            cal.set(Calendar.DAY_OF_MONTH,actualMaximum);
            //格式化日期,如果index=0为当前月，获取当前日期
            var lastDate = sdf.format(cal.getTime());

        }
        startAndEnd.add(lastDate);
        startAndEnd.add(month);
        return startAndEnd;
    },
    /**
     * 复制文件到指定目录
     * @param context
     * @param oldFile
     * @param fileName
     */
    filePathToLocal:function(context,oldFile,fileName,taskKey) {
        try {
            var year = taskKey.substring(0, 2);
            var month = taskKey.substring(2, 4);
            var day = taskKey.substring(4, 6);
            var filePath = PropertyManager.getRB("htmlStorage", "home_path") +"\\" +"BANK" + "\\" +
                year + "\\" + month + "\\"  + day + "\\" + taskKey + "\\" + fileName;
            logger.error("浦发借记卡，filePath:{}", filePath);
            FileUtils.copyFile(new File(oldFile),new File(filePath));
            return filePath;
        }catch (e) {
            statCaughtException(context, e);
            logger.error("浦发借记卡，在filePathToLocal 方法中保存交易流水信息时出错，taskKey:{},{}", taskKey, e);
        }
    },
    /**
     * 借记卡 规范日期返回日期
     *
     * @param dateStr
     *            formatDate('20170507')
     * @return 2017-05-07
     */
    formatDate:function(dateStr) {
        if (dateStr==null || equals("",dateStr)) {
            return "";
        }
        dateStr = RegexUtils.GetText(dateStr, "(\\d+)");
        var d = null;
        try {
            dateStr = getDateStr(dateStr, "yyyy-MM-dd", "yyyy-MM-dd");
            d = DateUtils.parseDate(dateStr, "yyyyMMdd");
        } catch (e) {
            logger.error("解析日期格式出错" + dateStr, e);
        }
        dateStr = DateFormatUtils.format(d, "yyyy-MM-dd");
        return dateStr;
    },
    /**
     * 读取 office 2003 excel
     *
     * @throws IOException
     * @throws FileNotFoundException
     */
    read2003Excel:function (file) {
        var list = new LinkedList();
        //var hwb = new HSSFWorkbook(new FileInputStream(file));
        var hwb;
        try {
            hwb = new HSSFWorkbook(new FileInputStream(file));
        }catch (e) {
            hwb = new HSSFWorkbook(new FileInputStream(file));
        }
        var sheet = hwb.getSheetAt(0);
        var value = null;
        var row = null;
        var cell = null;
        var counter = 0;
        for (var i = sheet.getFirstRowNum(); counter < sheet.getPhysicalNumberOfRows(); i++) {
            row = sheet.getRow(i);
            if (row == null) {
                continue;
            } else {
                counter++;
            }
            var linked = new LinkedList();
            for (var j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
                cell = row.getCell(j);
                if (cell == null) {
                    linked.add("");
                } else {
                    linked.add(cell.toString());
                }

            }
            list.add(linked);
        }
        return list;
    },
    /**
     * 获取六个月内的开始时间和结束时间
     */
    get6MonthStartAndEnd:function(currentMonth,calendar){
        var startAndEnd=new Array(2);
        var monthStr="";
        //String dayStr="";
        var endMonthStr="";
        var endDay="";
        var endMonth = calendar.get(Calendar.MONTH)+1;
        var endYear=calendar.get(Calendar.YEAR);
        var endDaysss=calendar.get(Calendar.DAY_OF_MONTH);
        //开始时间 20170911    20170301
        var   startMonth=0;
        if (endMonth==currentMonth) {//如果是当前月分
            calendar.add(Calendar.MONTH, -5);
            startMonth = calendar.get(Calendar.MONTH)+1;
            if (endDaysss<10) {
                endDay="0"+endDaysss;
            }else {
                endDay=Integer.toString(endDaysss);
            }
        }else{
            calendar.add(Calendar.MONTH, -5);
            startMonth = calendar.get(Calendar.MONTH)+1;
            endDay="30";
        }
        var year=calendar.get(Calendar.YEAR);
        //int day=calendar.get(Calendar.DAY_OF_MONTH);
        if (startMonth<10) {
            monthStr="0"+startMonth;
        }else{
            monthStr=Integer.toString(startMonth);
        }
        if (endMonth<10) {
            endMonthStr="0"+endMonth;
        }else{
            endMonthStr=Integer.toString(endMonth);
        }
        startAndEnd[0]=year+monthStr+"01";
        startAndEnd[1]=endYear+endMonthStr+endDay;
        calendar.add(Calendar.MONTH, -1);
        return startAndEnd;
    },
    /**
     * 借记卡 返回月份
     *
     * @param dateStr
     *            formatDate('20170507')
     * @return 2017-05-07
     */
    formatMonth:function(dateStr) {
        dateStr = RegexUtils.GetText(dateStr, "(\\d+)");
        var d = null;
        try {
            d = DateUtils.parseDate(dateStr, "yyyyMMdd");
        } catch (e) {
            logger.error("解析日期格式出错" + dateStr, e);
        }
        dateStr = DateFormatUtils.format(d, "yyyy-MM");
        return dateStr;
    },
    /**
     * 解析map并拼接参数
     * @returns {string}
     */
    mapParemsEntrySet:function (parems) {
        var paremStr = "";
        var entrySet = parems.entrySet();
        // for(var i=0;i<entrySet.size();i++){
        for each(var entry in entrySet){
            var key = entry.getKey();
            var value=entry.getValue();
            paremStr=paremStr+key+"="+value+"&";
        }
        return paremStr;
    },
    getTimeMonthToNumMonth: function (num, time) {
        var d = new Date(time.replace(/-/g,"/"));
        d.setMonth(d.getMonth() - num);
        var nowTime = TimeUtil.getTimeStr(d,"yyyyMMdd");
        return nowTime;
    },
    /**
     * 获取未出账单的账单月
     * @param billDay
     */
    getUnBillDataTime:function(billDay){
        var today= DateUtil.today();
        var  nowDay = today.substring(8,10);
        // 获取当月的第几日
        var dayMonth = DateUtil.date();
        // 当前时间和账单日对比
        if(nowDay > billDay){
            dayMonth = DateUtil.nextMonth();
        }
        var dateStr = dayMonth.toString();
        return getDateStr(dateStr,"yyyy-MM-dd HH:mm:ss","yyyy-MM")
    },
}